<?php

      function dbConnector($connInfoFile, $query){   
  
        if($connInfoFile != ''){
             
                $file = fopen($connInfoFile, "r");
                if($file){
            
                    $contents = fread($file, filesize($connInfoFile));    
                    $connInfo = json_decode($contents, true) or die("Error in decoding $connInfoFile \n");
            
                    $connection = mysql_connect($connInfo['host'], $connInfo['user'], $connInfo['passwd'], true) or die("Could not create connection to: ". $connInfo['schema'] . " " . mysql_error($connection). "\n");
                    $selected_db = mysql_select_db($connInfo['schema'], $connection) or die("Could not select schema: ". mysql_error($connection). " \n");
                    
                    $result = mysql_query($query, $connection);
                    
                    if(false == $result){
                        print("Error no: ". mysql_errno($connection). " : ".mysql_error($connection) . "\n");
                        die(" Could not execute query: $query \n");
                }
        
                   mysql_close($connection);
                          
                    return $result;            
                }else{
                   die("Unable to open global db info file\n");     
                   }                                    
        }else{           
             die("Blank file passed to local DB Manager\n");        
        }        
     }

?>
